/*
 * Copyright(C) 2021. Huawei Technologies Co.,Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef YOLOV8_POST_PROCESS_H
#define YOLOV8_POST_PROCESS_H
#include "MxBase/PostProcessBases/ObjectPostProcessBase.h"

namespace {
const float DEFAULT_OBJECTNESS_THRESH = 0.3;
const float DEFAULT_IOU_THRESH = 0.45;
}


class Yolov8PostProcess : public MxBase::ObjectPostProcessBase {
public:
    Yolov8PostProcess() = default;

    ~Yolov8PostProcess() = default;

    Yolov8PostProcess(const Yolov8PostProcess &other) = default;

    Yolov8PostProcess &operator=(const Yolov8PostProcess &other);

    APP_ERROR Init(const std::map<std::string, std::shared_ptr<void>> &postConfig) override;

    APP_ERROR DeInit() override;

    APP_ERROR Process(const std::vector<MxBase::TensorBase> &tensors, std::vector<std::vector<MxBase::ObjectInfo>> &objectInfos,
                      const std::vector<MxBase::ResizedImageInfo> &resizedImageInfos = {},
                      const std::map<std::string, std::shared_ptr<void>> &paramMap = {}) override;
protected:
    void ObjectDetectionOutput(const std::vector<MxBase::TensorBase> &tensors,
                               std::vector<std::vector<MxBase::ObjectInfo>> &objectInfos,
                               const std::vector<MxBase::ResizedImageInfo> &resizedImageInfos = {});
    void ConstructBoxFromOutput(float *output, size_t rows, std::vector<MxBase::ObjectInfo> &objectInfo, 
                                const MxBase::ResizedImageInfo &resizedImageInfo);

protected:
    float objectnessThresh_ = DEFAULT_OBJECTNESS_THRESH; // Threshold of objectness value
    float iouThresh_ = DEFAULT_IOU_THRESH; // Non-Maximum Suppression threshold
    int paddingType_ = 1;
};
#endif